package com.sw.study.springmvc;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * Created by sw on 2020/4/7.
 */
@Controller
@RequestMapping("/demo")
public class Democontroller {
    /***
     * springmvc  在handler方法上传入map model和ModelMap参数，并向这些参数中保存数据（放入到请求域），
     * 都可以在页面中获取到，他们的关系是什么？
     * 运行时的具体类型都是BindingAwareModelMap 相当于给BindingAwareModelMap中保存的数据都会放在请求域中
     *
     * Map （jdk中的接口）
     * Model (Spring中的接口)
     *
     * ModelMap （ class 实现LinkedMap接口）
     * BindingAwareModelMap  继承了 ExtendedModelMap  ---》继承了ModelMap 实现了Model 接口
     *
     *
     */


    /**
     *
     */
    @RequestMapping("handle01")
    public ModelAndView handle01 (){
        LocalDate date= LocalDate.now();
        //
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("date",date.toString());
        /**
         * 视图信息
         */
        modelAndView.setViewName("success");
        return modelAndView;
    }


    /**
     *
     */
    @RequestMapping("handle11")
    public String  handle11 (ModelMap map){
        System.out.println("___________modelMap:"+map);
        LocalDateTime date= LocalDateTime.now();
        map.put("date",date.toString());

        return "success";
    }

    @RequestMapping("handle12")
    public String  handle12 (Map<String,Object> map){
        System.out.println("___________map:"+map);

        LocalDateTime date= LocalDateTime.now();
        map.put("date",date.toString());

        return "success";
    }


    @RequestMapping("handle13")
    public String  handle13 (Model model){
        System.out.println("___________model:"+model.getClass());
        LocalDateTime date= LocalDateTime.now();
        model.addAttribute("date",date.toString());
        return "success";
    }


}